<?php
/**
 * 系统的一些参数的配置
 */

class openapi_ctl_admin_params extends desktop_controller{
	 public function __construct($app){
         parent::__construct($app);
         $this->paramObj = kernel::single('openapi_params');
     }
	public function index(){

		$params_arr = kernel::single('openapi_params')->getAppParams('set');
		$params = $params_arr['content']['cols'];
        $sdata = $this->paramObj->getParams();

        foreach ($params as $key => $value) {
            $params[$key]['value'] = $sdata[$key];//app::get('openapi')->getConf('params_setting',$_POST);
        }
        $this->pagedata['params'] = $params;

		$this->page('admin/params/setting.html');
	}
    function save(){

        $this->begin();
        $msg = $this->check($_POST);

        if($msg == 1){
            if( $this->paramObj->setParams($_POST) ){
                $this->end(true,app::get('openapi')->_('保存成功'));
            }else{
                $this->end(false,app::get('openapi')->_('保存失败'));
            }
        }else{
            $this->end(false,app::get('openapi')->_($msg));
        }
    }
    /*
    * 验证
    * */
    function check($data){
        $params_data['content'] = json_encode($data);
        $result = kernel::single('openapi_params')->checkParams('set',$params_data,$sub_msg);
        if($result){
            return 1;
        }else{
            return $sub_msg;
        }

    }

    function getParams(){
       print_r($this->app->getConf('params_setting'));
    }

}